package com.pan.hisystem.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.regex.Pattern;

/**
 * @Description 生成卡号工具类
 * @Author jia
 * @Date 2022/3/12 18:29
 * @Version 1.0
 **/
public class IdUtils {

    private static final String REGEX_MOBILE ="((\\+86|0086)?\\s*)((134[0-8]\\d{7})|(((13([0-3]|[5-9]))|(14[5-9])|15([0-3]|[5-9])|(16(2|[5-7]))|17([0-3]|[5-8])|18[0-9]|19(1|[8-9]))\\d{8})|(14(0|1|4)0\\d{7})|(1740([0-5]|[6-9]|[10-12])\\d{7}))";

    /**
     * 生成就诊卡号字符串
     * @return
     */
    public static String getMId(){
        Random r=new Random();
        char str=0;
        int num=0;
        List list=new ArrayList<String>();//将生成的六个随机字符存入该集合
        for(int i=0;i<6;i++){
            int a=r.nextInt(9);
            //随机选择生成字母或数字
            if(a%2==1){
                str = (char)(Math.random()*26+'A');
                list.add(str);
            }
            else{
                num=r.nextInt(9);
                list.add(num);
            }
        }
        //将集合转化为字符串
        StringBuffer sb=new StringBuffer();
        for (Object o : list) {
            sb.append(o);
        }
        return sb.toString();

    }


    /**
     * 判断是否是手机号
     * @param tel 手机号
     * @return boolean true:是  false:否
     */
    public static boolean isMobile(String tel) {
        if (StringUtils.isEmpty(tel)){ return false;}
        return Pattern.matches(REGEX_MOBILE, tel);
    }

    /**
     * 生成处方号
     * @return
     */
    public static int getPrescriptionId(){
        Random random=new Random();
        int num=0;
        for(int i=0;i<6;i++){
            int k=random.nextInt(9);
            num=num*10+k;
        }
        return num;
    }
}
